﻿Imports VN.INS.BL.BC
Imports System.Data
Imports System.IO

Partial Class Devida_ListaPoaHistorico
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not (Page.IsPostBack)) Then
            'captura de parametros
            ViewState("VSPOA") = Request.QueryString("POA").ToString
            ViewState("VSVERSION") = Request.QueryString("VERSION").ToString
            'carga de datos
            Cargarpoah(ViewState("VSPOA"), ViewState("VSVERSION"))
            carga_grillacnh(ViewState("VSPOA"), ViewState("VSVERSION"))
            carga_grillafh(ViewState("VSPOA"), ViewState("VSVERSION"))
            carga_grillafnh(ViewState("VSPOA"), ViewState("VSVERSION"))
        End If
    End Sub

    'carga de pestaña principal
    Public Sub Cargarpoah(ByVal poah As String, ByVal VERSION As String)
        Dim objPOAHBC As ListaPoaHistoricoBC
        Dim objData As DataTable
        objPOAHBC = New ListaPoaHistoricoBC
        objData = objPOAHBC.ListaPoaHistorico(poah, VERSION)
        txt_nom.Text = objData.Rows(0).Item("nombre").ToString
        txt_obj.Text = objData.Rows(0).Item("objetivo").ToString
        txt_mt1.Text = objData.Rows(0).Item("meta").ToString
        txt_mt2.Text = objData.Rows(0).Item("meta2").ToString
        txt_mt3.Text = objData.Rows(0).Item("meta3").ToString
        txt_um1.Text = objData.Rows(0).Item("unidad").ToString
        txt_um2.Text = objData.Rows(0).Item("unidad2").ToString
        txt_um3.Text = objData.Rows(0).Item("unidad3").ToString
        txt_montoinvertido.Text = objData.Rows(0).Item("monto_total_invertido").ToString
        txt_montoia.Text = objData.Rows(0).Item("monto_inv_anhio").ToString
        txt_Afirma.Text = objData.Rows(0).Item("anhio_firma_poa").ToString
        txt_mesfirma.Text = objData.Rows(0).Item("mes_firma_poa").ToString
        txt_departamento.Text = objData.Rows(0).Item("departamento").ToString
        txt_proac.Text = objData.Rows(0).Item("tipo").ToString
        txt_snip.Text = objData.Rows(0).Item("snip").ToString
        txt_fechav.Text = objData.Rows(0).Item("fecha_viabilidad").ToString
        txt_ambito.Text = objData(0).Item("ambito").ToString
        txt_estado.Text = objData(0).Item("estado").ToString
        txt_pper.Text = objData(0).Item("pper").ToString
        txt_documento.Text = objData(0).Item("documento").ToString
        txt_ejecutor.Text = objData(0).Item("ejecutor").ToString
        txt_tipoingreso.Text = objData(0).Item("tp").ToString
        txt_version.Text = objData(0).Item("version").ToString
        txt_producto.Text = objData(0).Item("producto").ToString
        txt_monitoreador.Text = objData(0).Item("MONITOREADOR").ToString
        txt_especialista.Text = objData(0).Item("ESPECIALISTA").ToString
        txt_tipo_proy_des.Text = objData(0).Item("TIPO_PROYECTO_DES").ToString
        txt_MontoTransferido.Text = objData(0).Item("MONTO_TRANSFERIDO").ToString
        txt_tipo_transferencia.Text = objData(0).Item("TIPO_ASIGNACION_RECURSO").ToString
        txt_CoordX.Text = objData(0).Item("COORDX").ToString
        txt_CoordY.Text = objData(0).Item("COORDY").ToString
        txt_Obs.Text = objData(0).Item("OBSERVACION").ToString
    End Sub

    'carga de de metas financieras
    Public Sub carga_grillafh(ByVal poahfin As String, ByVal hfinVersion As String)
        Dim objFinancierohBC As ListaPoaHistoricoBC = New ListaPoaHistoricoBC
        Dim dtFinancieroh As DataTable
        dtFinancieroh = objFinancierohBC.ListaHFinanciero(poahfin, hfinVersion)
        gv_financierah.DataSource = dtFinancieroh
        gv_financierah.DataBind()
    End Sub

    'carga de metas fisicas
    Public Sub carga_grillafnh(ByVal poahfis As String, ByVal hfisVersion As String)
        Dim objFisicohBC As ListaPoaHistoricoBC = New ListaPoaHistoricoBC
        Dim dtFisiscoh As DataTable
        dtFisiscoh = objFisicohBC.ListaHFisico(poahfis, hfisVersion)
        gv_fisicah.DataSource = dtFisiscoh
        gv_fisicah.DataBind()
    End Sub

    'carga de componentes
    Public Sub carga_grillacnh(ByVal poahcom As String, ByVal hcomVersion As String)
        Dim objcomhBC As ListaPoaHistoricoBC = New ListaPoaHistoricoBC
        Dim dtcomh As DataTable
        dtcomh = objcomhBC.ListaHComponente(poahcom, hcomVersion)
        gv_comh.DataSource = dtcomh
        ViewState("dtcomponente") = dtcomh
        gv_comh.DataBind()
    End Sub

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        'redirecciona a poa historico
        Response.Redirect("Poa_historico.aspx?Param=" & ViewState("VSPOA"))

    End Sub

    Private _total1, _total2, _total3, _total4, _total5, _total6, _total7, _total8, _total9, _total10, _total11, _total12, _totalR As Decimal
    Protected Sub gv_financierah_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_financierah.RowDataBound
        'Llenado de metas financieras totales
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(4))
            Me._total1 = Me._total1 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(2).Text = "Totales"
            e.Row.Cells(3).Text = Me._total1.ToString("##,##0.00")
            e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(2).Font.Size = 7
            e.Row.Cells(3).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(5))
            Me._total2 = Me._total2 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then            
            e.Row.Cells(4).Text = Me._total2.ToString("##,##0.00")
            e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(6))
            Me._total3 = Me._total3 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then            
            e.Row.Cells(5).Text = Me._total3.ToString("##,##0.00")
            e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(7))
            Me._total4 = Me._total4 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(6).Text = Me._total4.ToString("##,##0.00")
            e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(8))
            Me._total5 = Me._total5 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(7).Text = Me._total5.ToString("##,##0.00")
            e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(9))
            Me._total6 = Me._total6 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(8).Text = Me._total6.ToString("##,##0.00")
            e.Row.Cells(8).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(10))
            Me._total7 = Me._total7 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(9).Text = Me._total7.ToString("##,##0.00")
            e.Row.Cells(9).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(11))
            Me._total8 = Me._total8 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(10).Text = Me._total8.ToString("##,##0.00")
            e.Row.Cells(10).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(12))
            Me._total9 = Me._total9 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(11).Text = Me._total9.ToString("##,##0.00")
            e.Row.Cells(11).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(13))
            Me._total10 = Me._total10 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(12).Text = Me._total10.ToString("##,##0.00")
            e.Row.Cells(12).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(14))
            Me._total11 = Me._total11 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(13).Text = Me._total11.ToString("##,##0.00")
            e.Row.Cells(13).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(15))
            Me._total12 = Me._total12 + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(14).Text = Me._total12.ToString("##,##0.00")
            e.Row.Cells(14).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim _Row As System.Data.DataRowView = e.Row.DataItem
            Dim price As Decimal = Convert.ToDecimal(_Row.Item(16))
            Me._totalR = Me._totalR + price
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(15).Text = Me._totalR.ToString("##,##0.00")
            e.Row.Cells(15).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(15).Font.Size = 7
        End If
    End Sub

    Private Function CuentaCaracter(ByVal cadena As String, ByVal caracter As Char) As Integer
        'cuenta el numero de caracteres en una cadena
        Dim contador As Integer
        contador = 0
        For Each c As Char In cadena.ToCharArray
            If c.ToString.Equals(caracter.ToString) Then
                contador = contador + 1
            End If
        Next
        Return contador
    End Function

    Protected Sub gv_fisicah_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_fisicah.RowDataBound
        'damos formato a grilla de metas fisicas
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim intPart As Int16
            Dim Comp As Label = CType(e.Row.FindControl("lblComp"), Label)
            Dim lblCOD As String = e.Row.Cells(2).Text

            Dim strPart As String()
            strPart = Split(lblCOD, ".")

            If strPart(0) = "&nbsp;" Then
            Else
                intPart = CInt(strPart(0))
                e.Row.Cells(0).Text = intPart.ToString
                If intPart Mod 2 = 1 Then
                    e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(200, 225, 250)
                    e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(200, 225, 250)
                Else
                    e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(235, 250, 255)
                    e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(235, 250, 255)
                End If
            End If

            Dim intContador As Int16 = CuentaCaracter(lblCOD, ".")
            If intContador = 1 Then
                For n As Int16 = 2 To 18
                    e.Row.Cells(n).BackColor = Drawing.Color.LightGray
                Next
            Else
                For n As Int16 = 2 To 18
                    e.Row.Cells(n).BackColor = Drawing.Color.WhiteSmoke
                Next
            End If
        End If
    End Sub

    Protected Sub btnHidden_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHidden.Click
        gv_comh.DataSource = Nothing
        gv_comh.DataBind()
    End Sub
End Class